package com.byhealth.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.byhealth.bean.CommonResponse;
import com.byhealth.codeTable.service.CodeTableService;
import com.byhealth.service.TestService;
import com.byhealth.utils.PropertiesUtil;

/**
 * 关键词
 * @author cenxi
 *
 */
@Controller
@RequestMapping("/test")
public class TestController extends BaseAction{
	
	@Resource
	private CodeTableService codeTableService;
	
	@Resource 
	private TestService testService;

	@ResponseBody
	@RequestMapping(value="/testTransaction")
	public CommonResponse testTransaction(String openid,HttpServletRequest request){
		CommonResponse response = new CommonResponse();
		//测试事务
		testService.test();
		
		return response;
	}
	
	@ResponseBody
	@RequestMapping(value="/login")
	public CommonResponse login(String name,HttpServletRequest request){
		CommonResponse response = new CommonResponse();

		request.getSession().setAttribute(PropertiesUtil.getConfig().getString("LOGIN_FLAG"), name);

		System.out.println("*********************");
		
		System.out.println(PropertiesUtil.getConfig().getString("LOGIN_FLAG"));
		
		System.out.println("Sessionid-->>"+request.getSession().getId());
		
		System.out.println(request.getSession().getAttribute(PropertiesUtil.getConfig().getString("LOGIN_FLAG")));
		
		System.out.println("*********************");
		
		return response;
	}
	
	@ResponseBody
	@RequestMapping(value="/afterLogin")
	public CommonResponse test(HttpServletRequest request){
		CommonResponse response = new CommonResponse();
		String name = (String)request.getSession().getAttribute(PropertiesUtil.getConfig().getString("LOGIN_FLAG"));
		response.setData(name);
		return response;
	}
}
